<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="180px"
    >

      <el-form-item label="供应商名称" prop="supplierName">
        <el-input
          v-model="queryParams.supplierName"
          placeholder=""
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
      >新增
      </el-button>
    </el-row>

    <el-table v-loading="loading" :data="tableData">
      <el-table-column label="供应商名称" align="center" prop="supplierName"/>
      <el-table-column label="投诉负责人" align="center" prop="complaintHeader"/>
      <el-table-column label="投诉电话" align="center" prop="complaintTel"/>
      <el-table-column label="旅行社" align="center" prop="travelAgency"/>
      <el-table-column label="许可证" align="center" prop="permitCard"/>
      <el-table-column label="签约时效" align="center" prop="endDate"/>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">

          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(scope.row)"
          >详情
          </el-button>


          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>


          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <Create ref="createDialog"/>
    <Detail ref="detailDialog"/>
  </div>
</template>

<script>
import {pageList, deleteById} from "@/api/system/supplier"
import {pageList as linePageList} from "@/api/system/line"
import Create from "@/views/system/supplier/create";
import Detail from "@/views/system/supplier/detail";

export default {
  name: "organization",
  components: {Create, Detail},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        supplierName: ""
      },
      oneLine:[],
      lineVo:{
        "parentId":0
      }
    }
  },
  created() {
    this.getList()
    this.getOneLine(this.lineVo);
  },
  methods: {
    /** 查询合同列表 */
    getList() {
      this.loading = true
      pageList(this.queryParams).then(response => {
          this.tableData = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    getOneLine(vo){
      linePageList(vo).then(response=>{
        this.oneLine=response.rows;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.createDialog.open()
    },
    /** 查看详情操作 */
    handleDetail(row) {
      this.$refs.detailDialog.open(row.id)
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.createDialog.open(row.id)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除？').then(function () {
        return deleteById(row.id)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },
  }
}
</script>
